//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "editor\fn_weakVehicle.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_multiplier"];
DEFAULT_PARAM(_object,0,objNull);
DEFAULT_PARAM(_multiplier,1,4);

if !(isNull _object) then {
	_object setVariable [QGVAR(PREVIOUS_DAMAGE),damage _object];
	_object setVariable [QGVAR(DAMAGE_MULTIPLIER),_multiplier];
	_object addEventHandler ["HandleDamage",{
		if ((_this select 1) == "") then {
			private ["_dmg","_prev"];
			_dmg = _this select 2;
			// unit, selectionName, damage, source, projectile 
			if (isPlayer(_this select 3)) then {
				_prev = (_this select 0) getVariable [QGVAR(PREVIOUS_DAMAGE), _dmg];
				_dmg = _prev + (_dmg - _prev) * ((_this select 0) getVariable [QGVAR(DAMAGE_MULTIPLIER),4]);
			} else {
				(_this select 0) setVariable [QGVAR(PREVIOUS_DAMAGE), _dmg];
			};
			TRACE_2("Result",_this,_dmg);
			_dmg;
		};
	}];
};
TRACE("End");
TMFPROFILERSTOP;